#!/usr/bin/env python

import Queue
import heapq
import random as rand

from Queue import Queue
from heapq import heappush, heappop

def get_prop(props, prop_name, def_val=None, must_exist=False):
  if prop_name in props:
    return props[prop_name]
  else:
    if must_exist:
      raise Exception('Property %s must exist.' % (prop_name))
    else:
      return def_val

def gen_id(fr, to, id_set):
  r = rand.randint(fr, to)
  while r in id_set:
    r = rand.randint(fr, to)
  return r

def cross_prod(l1, l2):
  l = []
  for i1 in l1:
    for i2 in l2:
      l.append((i1, i2))
  return l


def test_test(test):
  print test

class PriorityQueue(Queue):
    # Initialize the queue representation
    def _init(self, maxsize):
        self.maxsize = maxsize
        self.queue = []
        self.it = 0

    # Put a new item in the queue
    def _put(self, item):
        return heappush(self.queue, item)

    # Get an item from the queue
    def _get(self):
        return heappop(self.queue)
    
    def __iter__(self):
      self.it = 0
      return self
    
    def next(self):
      if self.it >= len(self.queue): raise StopIteration
      a = self.queue[self.it]
      self.it += 1
      return a
      

if __name__ == "__main__":
    q = PriorityQueue()
    q.put((2,"a"))
    q.put((0,"b"))
    q.put((1,"c"))
    
    q.put((2,"d"))
    q.put((1,"e"))
    
    #for i in q: print i,
    
    while not q.empty():
        print q.get()
